/* IMPLEMENATION OF K-MEANS FOR PURE DATA: UNSUPERVISIONED MACHINE LEARNING ALGORITHM
 * FOR DATA CLUSTERIZATION.
 *  
 *  by Adriano Monteiro, december, 27, 2012. contact: monteiro.adc@gmaill.com
 *  
 */

#include "m_pd.h"
#include <stdlib.h>
#include <math.h>


static t_class *wav2aud_class;

#define L 26
#define M 129

static float r_COCHBA[L][M] = {22,22,24,22,20,19,21,19,18,18,17,16,14,15,14,15,15,14,13,12,14,14,12,12,12,12,11,12,11,10,10,9,10,10,9,9,9,9,8,10,11,13,12,11,12,12,10,10,10,9,11,9,10,8,8,9,13,9,10,9,8,9,8,8,8,8,8,8,10,7,9,7,7,7,7,9,9,7,7,7,7,8,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,8,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
		0.0029227,0.0030078,0.0030963,0.0031871,0.0032798,0.0033756,0.0034749,0.0035769,0.0036812,0.0037892,0.0038998,0.004013,0.0041315,0.0042519,0.0043765,0.0045051,0.0046367,0.0047727,0.0049114,0.0050558,0.0052038,0.0053561,0.0055132,0.0056742,0.0058404,0.0060114,0.0061875,0.0063685,0.006555,0.0067472,0.0069445,0.007148,0.0073571,0.0075725,0.0077943,0.0080225,0.0082574,0.0084992,0.0087482,0.0090043,0.0092679,0.0095387,0.009818,0.010106,0.010402,0.010706,0.01102,0.011343,0.011675,0.012017,0.012369,0.012731,0.013104,0.013488,0.013883,0.01429,0.014709,0.015139,0.015583,0.016039,0.016509,0.016993,0.01749,0.018003,0.01853,0.019073,0.019632,0.020207,0.020799,0.021408,0.022036,0.022681,0.023345,0.024029,0.024733,0.025267,0.02612,0.026971,0.027762,0.028575,0.029412,0.030274,0.031161,0.032074,0.033013,0.03398,0.034976,0.036001,0.037055,0.038141,0.039258,0.040409,0.041593,0.042811,0.044065,0.045356,0.046685,0.048053,0.049461,0.050909,0.052401,0.053936,0.055516,0.057142,0.058815,0.060538,0.062311,0.064135,0.066013,0.067945,0.069933,0.071979,0.074084,0.076249,0.078476,0.080766,0.08312,0.085539,0.088024,0.090574,0.09319,0.095871,0.098615,0.10142,0.10429,0.10723,0.11027,0.11348,0.11698,
		-0.0017265,-0.001786,-0.0014379,-0.0019262,-0.002487,-0.0028125,-0.0023349,-0.0030782,-0.0034842,-0.0036411,-0.0041814,-0.0047551,-0.0062214,-0.0056282,-0.0065467,-0.0060902,-0.0062271,-0.007261,-0.0083208,-0.0096824,-0.0078232,-0.0080364,-0.010638,-0.010896,-0.011211,-0.011523,-0.01354,-0.012162,-0.014282,-0.016924,-0.017328,-0.02063,-0.018304,-0.018805,-0.022389,-0.023026,-0.023666,-0.024295,-0.029316,-0.022045,-0.027642,-0.024269,-0.028097,-0.032634,-0.029432,-0.030261,-0.039556,-0.041182,-0.042469,-0.049852,-0.038416,-0.052481,-0.046677,-0.062536,-0.064689,-0.058021,-0.051648,-0.060554,-0.070739,-0.062782,-0.075885,-0.071076,-0.08019,-0.081623,-0.08285,-0.084588,-0.086866,-0.11389,-0.096081,-0.11187,-0.11549,-0.11507,-0.11867,-0.12059,-0.12161,-0.17195,-0.17547,-0.12948,-0.13169,-0.13384,-0.13591,-0.16192,-0.13978,-0.14149,-0.14313,-0.14466,-0.14592,-0.14703,-0.14792,-0.14857,-0.14894,-0.1495,-0.1487,-0.14845,-0.14786,-0.14565,-0.14405,-0.14155,-0.13924,-0.13497,-0.1309,-0.12557,-0.12084,-0.11358,-0.10766,-0.098841,-0.10346,-0.064899,-0.072884,-0.058433,-0.043191,-0.028756,-0.022151,0.0034919,0.022076,0.04114,0.063081,0.085377,0.10433,0.13442,0.15816,0.18706,0.2145,0.2462,0.27577,0.30748,0.34052,0.19194,0.20328,
		-0.0026102,-0.0026806,-0.0025923,-0.0028438,-0.0030481,-0.0031816,-0.0031687,-0.003347,-0.0034558,-0.0035328,-0.0035718,-0.0035597,-0.0029662,-0.0035342,-0.0031721,-0.0036237,-0.0037527,-0.0032981,-0.002683,-0.0015611,-0.0036582,-0.0037701,-0.0015167,-0.0016216,-0.0016556,-0.0017105,0.00065149,-0.0018364,0.00062569,0.0046919,0.0046534,0.011137,0.0048912,0.0050001,0.01202,0.012387,0.012724,0.012987,0.025758,0.0056287,0.015932,0.0062821,0.013172,0.023154,0.013504,0.013969,0.037952,0.040802,0.042206,0.066381,0.025716,0.069687,0.045032,0.10662,0.11129,0.075754,0.045496,0.077874,0.11473,0.078614,0.12976,0.1047,0.13715,0.13798,0.13804,0.13975,0.14355,0.28115,0.16195,0.24899,0.2434,0.24946,0.25828,0.2596,0.25709,0.52322,0.52848,0.2692,0.27129,0.27302,0.27437,0.3927,0.27581,0.27558,0.27507,0.27415,0.27225,0.26981,0.26669,0.26283,0.25813,0.25411,0.24605,0.23985,0.23282,0.22155,0.21229,0.20105,0.19064,0.17617,0.16273,0.14737,0.13379,0.11646,0.10214,0.084366,0.082884,0.061097,0.037537,0.019253,0.0027233,-0.011277,-0.022918,-0.034226,-0.04229,-0.047675,-0.048955,-0.0467,-0.044389,-0.027793,-0.013781,0.01113,0.038627,0.078224,0.11944,0.1702,0.2295,-0.12764,-0.12436,
		-0.0016631,-0.0016979,-0.0019658,-0.0017634,-0.0014198,-0.0012354,-0.0017498,-0.0011798,-0.00088477,-0.00083355,-0.0003436,0.00022467,0.0021357,0.001067,0.0022106,0.0013338,0.0013126,0.002606,0.0039324,0.0057337,0.0027147,0.0027812,0.006336,0.0064403,0.0066284,0.0068071,0.0091592,0.0071652,0.0096385,0.011968,0.01225,0.01332,0.012916,0.013263,0.014359,0.014706,0.015072,0.015506,0.011008,0.015468,0.018043,0.017602,0.019694,0.019338,0.020471,0.02088,0.014633,0.013343,0.013773,-0.0076204,0.022475,-0.0086115,0.015983,-0.061765,-0.066426,-0.0081697,0.024056,-0.007895,-0.052282,-0.0060191,-0.078629,-0.040432,-0.083737,-0.082636,-0.080823,-0.080546,-0.083552,-0.39594,-0.085239,-0.30179,-0.23505,-0.29536,-0.30814,-0.30709,-0.29928,-0.93137,-0.93427,-0.31175,-0.31261,-0.31299,-0.31286,-0.56242,-0.31098,-0.30877,-0.30637,-0.30357,-0.2995,-0.29494,-0.2897,-0.28376,-0.27704,-0.27181,-0.26127,-0.25403,-0.24626,-0.23354,-0.22435,-0.21348,-0.20452,-0.19179,-0.18141,-0.17017,-0.16197,-0.15148,-0.1451,-0.1373,-0.1416,-0.14581,-0.12785,-0.12727,-0.1297,-0.13506,-0.13939,-0.15349,-0.16675,-0.18195,-0.20004,-0.21911,-0.23582,-0.25935,-0.277,-0.29482,-0.30794,-0.31727,-0.31926,-0.3134,-0.29754,-0.33198,-0.33669,
		-0.000175,-0.00016995,-0.00066274,-0.00012565,0.00053981,0.00091524,0.00017911,0.0011028,0.0015712,0.0016809,0.0022893,0.0029048,0.0042594,0.0037437,0.0044775,0.0040295,0.0041094,0.0048715,0.0053654,0.0055286,0.0052539,0.0053978,0.0058632,0.0060434,0.006196,0.0063654,0.0052202,0.0067205,0.0055392,0.0019931,0.0022408,-0.0049869,0.0023414,0.0024065,-0.0053165,-0.0055182,-0.0056614,-0.0057786,-0.019564,0.0028819,-0.0069482,0.0047501,-0.0019897,-0.013067,-0.0018976,-0.002106,-0.028342,-0.030072,-0.031353,-0.04816,-0.013771,-0.049376,-0.03346,-0.038472,-0.037386,-0.054326,-0.030009,-0.055133,-0.059181,-0.056076,-0.04079,-0.051507,-0.042557,-0.043997,-0.04504,-0.047097,-0.046912,0.34607,-0.072822,0.20662,0.033859,0.19711,0.20854,0.2062,0.19744,1.0582,1.0586,0.2069,0.20708,0.20692,0.20642,0.50966,0.20429,0.20225,0.20019,0.19795,0.19464,0.19105,0.18698,0.1824,0.17722,0.17363,0.165,0.15967,0.15387,0.14316,0.13586,0.1267,0.11929,0.10747,0.097586,0.085899,0.076937,0.063625,0.054508,0.040843,0.053518,0.0026105,0.0086312,-0.0097849,-0.028356,-0.04434,-0.044417,-0.079052,-0.099465,-0.11986,-0.14526,-0.17066,-0.18717,-0.22901,-0.25456,-0.292,-0.32419,-0.36618,-0.40007,-0.43673,-0.47262,-0.0095685,-0.0042012,
		0.0010863,0.0011165,0.00061268,0.0012284,0.0018605,0.0022067,0.0016405,0.0023864,0.0027327,0.0028151,0.0031186,0.0033225,0.0028936,0.0034689,0.0030927,0.0035228,0.0036456,0.0031403,0.0022711,0.00040725,0.0034901,0.0035888,0.00019682,0.0003082,0.00029178,0.00029196,-0.003262,0.00031742,-0.0033926,-0.0082923,-0.0083681,-0.012378,-0.0088092,-0.009051,-0.013246,-0.013518,-0.013875,-0.014235,-0.0085636,-0.010534,-0.017627,-0.010703,-0.01693,-0.020614,-0.017306,-0.017638,-0.016895,-0.015343,-0.015921,0.01401,-0.02293,0.014893,-0.01778,0.073062,0.074981,0.015758,-0.029673,0.015594,0.062916,0.014412,0.086239,0.055858,0.092243,0.092221,0.090985,0.092948,0.09482,-0.19211,0.092872,-0.071021,0.15447,-0.064696,-0.070641,-0.068975,-0.063996,-0.77963,-0.78221,-0.068735,-0.068881,-0.068932,-0.068888,-0.29035,-0.06851,-0.067937,-0.067496,-0.067084,-0.066198,-0.065297,-0.064268,-0.063103,-0.061746,-0.061422,-0.058444,-0.057422,-0.056255,-0.05264,-0.05093,-0.048399,-0.046776,-0.04326,-0.040723,-0.037617,-0.035508,-0.03222,-0.029979,-0.027009,-0.023795,-0.071832,-0.018326,-0.016618,-0.015805,-0.014437,-0.0050407,-0.012883,-0.013674,-0.014297,-0.018051,-0.0217,-0.019343,-0.03423,-0.038172,-0.051314,-0.061759,-0.080929,-0.096361,-0.1168,-0.14038,0.16109,0.16468,
		0.0017586,0.0017965,0.0014794,0.0019176,0.0022195,0.0023536,0.002241,0.0024233,0.002444,0.0024517,0.0022476,0.0018812,-0.00017129,0.0011723,-0.00012412,0.00097758,0.001076,-0.00040616,-0.0019777,-0.0042317,-0.00029511,-0.0003039,-0.0046699,-0.0046919,-0.0048417,-0.0049699,-0.0069982,-0.0052413,-0.0073588,-0.0067848,-0.0070869,8.47e-005,-0.0074439,-0.0076142,-1.1707e-005,2.4626e-005,8.324e-005,3.1047e-005,0.017212,-0.0088063,-0.0025402,-0.012537,-0.0094485,0.0012506,-0.0097371,-0.0097322,0.020597,0.021472,0.022789,0.036775,0.00077288,0.036787,0.024226,-0.034451,-0.036083,0.040963,0.01091,0.040864,0.024485,0.041486,-0.043028,-0.010169,-0.047395,-0.046482,-0.044711,-0.045525,-0.0471,0.067335,0.025747,0.0049578,-0.15836,0.0026574,0.0040861,0.0033871,0.0018824,0.35531,0.36156,0.002646,0.0025717,0.002499,0.0024295,0.093166,0.0023183,0.0022024,0.0021853,0.0022386,0.0021899,0.002207,0.0022549,0.0023377,0.0024402,0.0030633,0.0027189,0.0033059,0.0039891,0.0036755,0.0044005,0.0048747,0.0060448,0.0062581,0.0072439,0.007966,0.0097645,0.010538,0.012911,0.014175,0.024643,0.0099011,0.022812,0.024191,0.025832,0.028823,0.035571,0.035521,0.038846,0.042664,0.045869,0.04952,0.054271,0.056405,0.060453,0.062987,0.065846,0.067562,0.069587,0.070935,0.071991,0.021025,0.01782,
		0.0017743,0.0018057,0.0017963,0.0018858,0.0017136,0.0015563,0.0019827,0.0014833,0.0011462,0.0010805,0.00045142,-0.00030042,-0.0027117,-0.0014711,-0.0027898,-0.001762,-0.0017329,-0.0031636,-0.0041585,-0.0045898,-0.0033287,-0.0034198,-0.0047864,-0.0049262,-0.0050457,-0.0051765,-0.0029817,-0.0054539,-0.0031802,0.0031862,0.0030081,0.01045,0.0032042,0.0032869,0.011066,0.0113,0.011554,0.011917,-0.0048381,0.0038649,0.013856,-0.0014544,0.0080341,0.018135,0.0080139,0.0082628,0.016201,0.015011,0.015573,-0.029285,0.019402,-0.029168,0.016989,0.0024415,0.0027581,-0.032576,0.030451,-0.031661,-0.066081,-0.030929,0.003843,-0.004274,0.0050106,0.0043599,0.0034866,0.0034944,0.0038864,-0.014764,-0.087506,0.0026646,0.062435,0.0030978,0.0031028,0.0032918,0.0035079,-0.083363,-0.089118,0.0039084,0.0040718,0.004243,0.0044226,-0.010443,0.0048071,0.0050227,0.005238,0.0054572,0.0057028,0.0059552,0.0062199,0.0064976,0.0067917,0.0070405,0.0074336,0.0077323,0.0080438,0.0085122,0.0088759,0.0093047,0.009676,0.010212,0.010685,0.011238,0.011687,0.012328,0.012793,0.013471,0.012547,0.00099023,0.014972,0.016096,0.016973,0.017759,0.016696,0.019395,0.020308,0.021177,0.022225,0.023219,0.02347,0.025389,0.026211,0.027635,0.028765,0.030547,0.032046,0.034017,0.036476,-0.023864,-0.024995,
		0.0012575,0.0012771,0.0015964,0.0012896,0.00068364,0.00027994,0.0011197,0.00010416,-0.00045774,-0.00056058,-0.0013139,-0.0020539,-0.0031657,-0.0029626,-0.003363,-0.0031391,-0.0031934,-0.0035023,-0.0029766,-0.00076674,-0.0038179,-0.0039188,-0.00056527,-0.00074258,-0.00071577,-0.00072332,0.003802,-0.00074878,0.0039524,0.0070217,0.0072014,-0.0038718,0.0075543,0.0077516,-0.0038578,-0.0039486,-0.004049,-0.0041811,-0.00045823,0.009044,0.0064902,0.0096679,0.013289,0.0050392,0.013494,0.013552,-0.020034,-0.020017,-0.021584,0.0046326,0.0057637,0.004279,-0.022844,0.0016006,0.001657,0.0049017,0.0057807,0.0040709,0.040049,0.0032842,0.0019597,-0.0021605,0.0019677,0.002146,0.0023276,0.0024227,0.0024756,0.001876,0.047288,0,-0.0053265,0,0,0,0,0.0018246,0.0043466,0,0,0,0,-0.0017457,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.0067784,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
		0.00043788,0.00044706,0.0010175,0.00038929,-0.00045583,-0.0009616,7.7679e-006,-0.0011567,-0.0016995,-0.0017856,-0.002294,-0.0025953,-0.0014837,-0.0026155,-0.0016283,-0.0025461,-0.0026603,-0.0014414,0.00038247,0.0033776,-0.0017114,-0.0017538,0.0037205,0.0036475,0.0037806,0.0038879,0.0047259,0.0041084,0.0049776,-0.0034256,-0.0031538,-0.00027907,-0.003327,-0.0034214,-0.00042968,-0.00044263,-0.00045611,-0.00047046,0,-0.0040664,-0.011632,0.0089077,-5.2994e-005,-0.01519,0.00010396,-2.5974e-005,0.0032557,0.0035324,0.0042971,0.0011007,-0.015502,0.001257,0.0041202,0,0,0.0014212,-0.02387,0.0016857,-0.010644,0.001932,0,0.0020099,0,0,0,0,0,0,-0.0052342,0,-0.0020846,0,0,0,0,0.002456,0.002012,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
		-0.00042076,-0.00042175,0.00025328,-0.00052593,-0.0013282,-0.001735,-0.00099112,-0.0018629,-0.0021375,-0.0021597,-0.0021332,-0.0017791,0.0011201,-0.00074544,0.0010864,-0.00046751,-0.00059195,0.0014644,0.002997,0.0030746,0.0013869,0.001431,0.0031018,0.0032394,0.0033079,0.0033834,-0.002708,0.0035595,-0.0027435,-0.00018904,-0.0003707,0,-0.0003929,-0.0004048,0,0,0,0,0,-0.00048275,0.0021362,-0.0025626,-0.011539,0.0036208,-0.011488,-0.011499,0.0011645,0.0011081,0.0010133,0,0.0027233,0,0.0013012,0,0,0,-0.011612,0,0.0011297,0,0,0,0,0,0,0,0,0,-0.001901,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
		-0.0010887,-0.0010955,-0.00049931,-0.0012101,-0.0016882,-0.0018207,-0.0016004,-0.0018153,-0.0016606,-0.0016068,-0.00099654,-0.00010654,0.0025624,0.0014183,0.0026602,0.0017159,0.0016512,0.0028842,0.0021957,-0.002109,0.0030494,0.0031314,-0.002433,-0.0021506,-0.0022852,-0.0023472,-0.00026344,-0.0024862,-0.00034148,0,0,0,0,0,0,0,0,0,0,0,0.00064956,-0.0088824,0.0031804,0.00086129,0.0028315,0.0028114,0,0,0,0,0.001379,0,0,0,0,0,0.020516,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
		-0.0014053,-0.0014156,-0.0010704,-0.001501,-0.0014581,-0.0012217,-0.0016747,-0.0010797,-0.000511,-0.00040531,0.00053512,0.0014665,0.0013316,0.002354,0.0014968,0.0024204,0.0024676,0.001289,-0.001498,-0.00024016,0.001577,0.001616,-0.00012763,-0.00033036,-0.00029736,-0.00030582,0,-0.00032361,0,0,0,0,0,0,0,0,0,0,0,0,0,0.0027683,0.00086715,0,0.0010364,0.001073,0,0,0,0,0,0,0,0,0,0,-0.0038293,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
		-0.0013096,-0.0013251,-0.0013478,-0.0013496,-0.00075114,-0.00019639,-0.0012277,2.9748e-005,0.00078353,0.00088665,0.001644,0.001932,-0.0015612,0.0011145,-0.0015008,0.00083824,0.00099238,-0.0019697,-0.00044489,0,-0.0017944,-0.001847,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.00088851,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-0.0013014,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
		-0.0008479,-0.00087041,-0.001288,-0.00082055,0.00017243,0.00083451,-0.00041965,0.0010459,0.0015817,0.0016253,0.0016275,0.00082929,-0.00015522,-0.001298,-0.00027883,-0.0016856,-0.0015351,9.0241e-006,0,0,-0.00025518,-0.00026228,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
		-0.00016522,-0.00019396,-0.0009234,-8.1928e-005,0.00095954,0.0014047,0.0004728,0.0014844,0.0013895,0.001337,0.00035021,-0.00098986,0,-0.0003391,0,-3.417e-005,-0.0002037,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
		0.00052693,0.00049743,-0.0003519,0.00063458,0.0012746,0.0011833,0.0011309,0.0010553,0.00020262,7.4616e-005,-0.0011767,-0.00043732,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
		0.00099411,0.00097454,0.00027591,0.0010819,0.00092526,0.00020266,0.0012756,-9.5803e-005,-0.0010804,-0.0011797,-0.00015636,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
		0.0010468,0.0010525,0.0007888,0.0010738,3.1198e-005,-0.00084749,0.00079469,-0.0010892,-0.00016492,-4.0169e-005,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
		0.00061841,0.00066173,0.0010268,0.0005648,-0.00079455,-0.000303,-0.00013269,8.3487e-006,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
		-0.00013185,-5.6781e-005,0.00089257,-0.00024381,-0.00023208,0,-0.00086811,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

static float i_COCHBA[L][M] = {6.4888,6.787,6.8174,6.8274,6.8326,6.8307,6.8257,6.8258,6.8196,6.8291,6.8313,6.8296,6.8368,6.8276,6.8259,6.8239,6.8188,6.8313,6.821,6.8266,6.8195,6.8191,6.8226,6.8196,6.8217,6.8193,6.8203,6.8177,6.8153,6.8157,6.8113,6.814,6.8109,6.8114,6.8102,6.8097,6.809,6.8078,6.8066,6.8041,6.8053,6.8055,6.8044,6.8014,6.8006,6.799,6.7998,6.7998,6.7985,6.7975,6.7989,6.796,6.7932,6.7925,6.793,6.7919,6.7888,6.7895,6.791,6.7868,6.7881,6.792,6.7902,6.7886,6.785,6.7818,6.7831,6.7878,6.7852,6.7881,6.7875,6.7863,6.7815,6.7804,6.7849,6.7906,6.7911,6.7877,6.7848,6.7837,6.7895,6.7922,6.7888,6.7894,6.7921,6.7926,6.7935,6.7947,6.796,6.7974,6.7988,6.8001,6.8018,6.8031,6.8045,6.8061,6.8075,6.809,6.8102,6.8118,6.8132,6.8151,6.8169,6.8188,6.8187,6.8159,6.8137,6.8201,6.8102,6.8089,6.8056,6.7979,6.7879,6.7781,6.7625,6.7424,6.7176,6.6859,6.645,6.5944,6.5287,6.4456,6.3385,6.2003,6.0197,5.7806,5.4572,5.0069,4.3595,
		1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
		-1.5717,-1.581,-1.4387,-1.5728,-1.7388,-1.8196,-1.6429,-1.8183,-1.9164,-1.9194,-2.0381,-2.1726,-2.47,-2.3006,-2.4667,-2.2999,-2.3015,-2.4624,-2.6688,-2.8723,-2.4566,-2.4515,-2.8697,-2.8726,-2.8665,-2.8612,-3.1275,-2.8488,-3.1167,-3.4332,-3.4293,-3.8111,-3.4156,-3.4077,-3.7958,-3.7898,-3.7819,-3.7706,-4.2591,-3.3501,-3.8939,-3.4512,-3.7644,-4.1284,-3.7258,-3.7172,-4.4841,-4.5149,-4.5117,-5.0219,-3.9735,-4.985,-4.4148,-5.4993,-5.5141,-4.8939,-4.3288,-4.8213,-5.3125,-4.7214,-5.3971,-4.9561,-5.3623,-5.3034,-5.2321,-5.185,-5.1621,-6.3265,-5.3237,-5.9266,-5.9216,-5.7507,-5.7432,-5.6638,-5.548,-7.4208,-7.3096,-5.3782,-5.3023,-5.2227,-5.1393,-5.837,-4.9607,-4.8632,-4.7632,-4.6599,-4.5488,-4.4335,-4.3131,-4.1872,-4.0552,-3.9289,-3.7716,-3.6294,-3.4814,-3.3002,-3.1358,-2.9557,-2.7833,-2.5764,-2.3783,-2.1621,-1.9623,-1.7237,-1.5147,-1.264,-1.2356,-0.53056,-0.56558,-0.26194,0.041643,0.3225,0.48739,0.89728,1.1993,1.4948,1.8125,2.1204,2.3765,2.7442,3.0258,3.3476,3.6381,3.9553,4.2348,4.5177,4.7942,3.4484,3.5387,
		-0.30529,-0.29603,-0.37675,-0.29866,-0.17545,-0.10797,-0.24907,-0.10159,-0.0080716,0.00037358,0.13338,0.30186,0.75093,0.48224,0.74837,0.49352,0.4971,0.75815,1.1321,1.5507,0.75431,0.74845,1.5648,1.5741,1.5657,1.5585,2.1952,1.5409,2.1783,3.0538,3.0465,4.2745,3.0223,3.0073,4.2519,4.2431,4.2279,4.2,6.0583,2.8999,4.5231,3.0454,4.0096,5.2864,3.9286,3.9203,6.7744,6.9244,6.9127,9.281,4.9039,9.1766,6.6188,12.094,12.191,8.8589,6.1254,8.6224,10.999,8.2758,11.774,9.5853,11.656,11.418,11.133,10.948,10.881,18.034,11.354,15.656,14.969,14.84,14.837,14.484,13.964,25.374,24.699,13.287,12.982,12.666,12.341,16.206,11.661,11.3,10.937,10.57,10.184,9.7924,9.3938,8.9885,8.5755,8.1953,7.7304,7.3306,6.9297,6.4545,6.0479,5.6232,5.2398,4.805,4.4188,4.029,3.6986,3.3421,3.0613,2.7687,2.6736,2.5874,2.1721,2.0389,1.9711,1.9607,1.9232,2.1175,2.3003,2.5402,2.8801,3.277,3.6352,4.3067,4.8565,5.5859,6.3037,7.1836,8.0167,8.9355,9.9045,4.3265,4.4549,
		0.31161,0.32078,0.18607,0.31472,0.4827,0.56804,0.38645,0.56769,0.672,0.67436,0.79691,0.93282,1.2014,1.0592,1.2004,1.0527,1.0539,1.186,1.3192,1.4064,1.1816,1.178,1.3836,1.3812,1.3764,1.3731,1.3413,1.3655,1.3367,1.0713,1.071,0.33147,1.0667,1.0662,0.31005,0.30116,0.29816,0.31014,-1.5872,1.0595,0.20313,1.1289,0.6393,-0.35149,0.63564,0.61489,-2.0719,-2.3133,-2.2917,-5.8932,-0.2557,-5.866,-2.0798,-12.138,-12.383,-5.5259,-1.2823,-5.3297,-9.4234,-4.9618,-11.922,-7.6542,-11.792,-11.437,-11.02,-10.741,-10.698,-30.108,-10.677,-23.806,-19.659,-22.151,-22.218,-21.529,-20.49,-52.342,-50.48,-19.315,-18.767,-18.205,-17.63,-27.466,-16.446,-15.823,-15.206,-14.59,-13.944,-13.298,-12.647,-11.992,-11.331,-10.739,-10.001,-9.3883,-8.7801,-8.046,-7.4388,-6.8029,-6.2417,-5.5881,-5.0166,-4.4295,-3.9398,-3.3778,-2.9425,-2.4383,-2.4754,-1.2444,-1.2741,-0.80358,-0.3578,0.022931,0.16198,0.78658,1.2056,1.6273,2.1348,2.6622,3.083,3.9317,4.5756,5.4776,6.3668,7.5237,8.6398,9.9363,11.372,1.7972,1.7134,
		0.49502,0.49799,0.40278,0.49235,0.58306,0.62325,0.53495,0.61538,0.6488,0.64344,0.65843,0.64899,0.51,0.61065,0.50521,0.59378,0.59182,0.48455,0.27376,-0.028052,0.4816,0.482,-0.049983,-0.058358,-0.055896,-0.054095,-0.58941,-0.04815,-0.58317,-1.3787,-1.3715,-2.4409,-1.3596,-1.3518,-2.4126,-2.4035,-2.388,-2.3749,-3.3406,-1.2904,-2.5469,-1.2539,-2.0671,-3.0161,-2.009,-1.9993,-3.6535,-3.5904,-3.6105,-3.1114,-2.7109,-2.9365,-3.4769,2.0665,2.3718,-2.9228,-3.3085,-2.7898,-0.92122,-2.753,2.4335,-0.95115,2.4186,2.2566,2.0875,1.9255,2.0002,32.097,0.6173,22.464,11.166,20.603,20.779,20.034,18.867,71.675,68.648,17.767,17.22,16.663,16.095,30.91,14.935,14.325,13.729,13.138,12.516,11.901,11.283,10.666,10.047,9.5081,8.8112,8.256,7.7082,7.0306,6.4913,5.9262,5.4406,4.869,4.3844,3.8939,3.4991,3.0553,2.7249,2.3622,2.2993,2.4071,1.6058,1.3963,1.2512,1.1597,1.0313,1.1173,1.1803,1.2849,1.4817,1.7229,1.8978,2.435,2.813,3.4208,4.022,4.8668,5.6812,6.6696,7.8006,-0.86083,-1.1109,
		0.42147,0.41762,0.39906,0.41459,0.39349,0.37018,0.41046,0.36027,0.31277,0.30417,0.2163,0.087789,-0.30836,-0.068237,-0.30704,-0.079772,-0.082936,-0.31212,-0.62663,-0.97213,-0.31249,-0.30988,-0.96489,-0.96897,-0.96184,-0.95871,-1.3073,-0.94853,-1.2984,-1.4592,-1.4617,-0.99916,-1.4445,-1.4392,-0.96569,-0.9461,-0.94281,-0.94185,1.2246,-1.3968,-1.048,-1.4985,-1.4089,-0.67633,-1.3585,-1.3283,1.0825,1.2914,1.2774,4.9553,-0.6331,4.8316,1.1634,7.7926,7.6193,4.6115,0.0094363,4.3987,7.1361,4.1334,7.0867,6.1863,7.0283,6.8712,6.6401,6.6028,6.4633,-22.31,7.0088,-13.15,4.61,-11.931,-12.129,-11.66,-10.888,-67.513,-64.353,-10.328,-10.015,-9.6966,-9.3729,-23.587,-8.7123,-8.3633,-8.025,-7.6917,-7.3371,-6.987,-6.6363,-6.2853,-5.9323,-5.6367,-5.2241,-4.9137,-4.6067,-4.1996,-3.8923,-3.5608,-3.2856,-2.9365,-2.6484,-2.3456,-2.1138,-1.8249,-1.6278,-1.378,-1.5075,-0.94127,-0.87509,-0.65701,-0.45967,-0.31429,-0.31732,-0.051962,0.082982,0.20407,0.35837,0.50513,0.57901,0.86019,1.0147,1.2883,1.5395,1.9142,2.2575,2.6862,3.1824,-1.1509,-1.3062,
		0.22604,0.21823,0.27474,0.21833,0.10715,0.036523,0.17382,0.030489,-0.067663,-0.073248,-0.2057,-0.365,-0.71215,-0.52857,-0.71204,-0.52215,-0.52441,-0.69387,-0.84157,-0.88365,-0.69097,-0.68854,-0.85013,-0.84479,-0.84179,-0.83685,-0.58332,-0.83135,-0.5781,0.18943,0.18536,1.6695,0.18268,0.185,1.647,1.6329,1.6299,1.613,2.8274,0.17618,1.56,-0.16432,0.72702,2.0454,0.70193,0.70867,3.1834,3.0404,3.0852,1.6283,1.7965,1.4456,2.9413,-8.3139,-8.3078,1.4757,2.442,1.3515,-1.7578,1.3345,-7.881,-3.7001,-7.8686,-7.6263,-7.2939,-7.1957,-7.1121,9.8465,-3.0365,4.4246,-12.913,3.9855,4.0951,3.9342,3.6492,43.736,41.575,3.5185,3.4244,3.3286,3.2311,11.932,3.032,2.9251,2.8227,2.7225,2.6131,2.5055,2.397,2.2878,2.177,2.0904,1.951,1.8554,1.7596,1.6174,1.5175,1.4045,1.3141,1.1885,1.0871,0.97713,0.89464,0.78671,0.71289,0.61836,0.63179,0.9262,0.40901,0.33453,0.27439,0.22642,0.16998,0.15383,0.13248,0.11696,0.12,0.12834,0.11643,0.18172,0.20331,0.26851,0.3237,0.41837,0.49687,0.59745,0.71183,-0.42053,-0.44923,
		0.008115,-0.00029935,0.10535,0.0023183,-0.14949,-0.23489,-0.063666,-0.23401,-0.3339,-0.3332,-0.43796,-0.53396,-0.59504,-0.59908,-0.58403,-0.5802,-0.57949,-0.56128,-0.40928,-0.064493,-0.55755,-0.55549,-0.039035,-0.030607,-0.031266,-0.031677,0.6203,-0.032501,0.61581,1.4009,1.4042,1.3838,1.3907,1.3794,1.3435,1.3264,1.3085,1.3148,-2.565,1.3226,1.6223,1.083,1.6532,1.5246,1.5776,1.5498,-0.56276,-0.6929,-0.69626,-5.3827,1.3227,-5.0845,-0.64967,3.6034,3.6415,-4.9591,1.1559,-4.6346,-5.5508,-4.3671,3.5171,-0.12798,3.5431,3.4229,3.2564,3.21,3.195,-2.5146,-4.7404,-0.66196,9.8457,-0.59401,-0.61925,-0.59596,-0.54985,-18.798,-17.858,-0.54521,-0.53474,-0.52409,-0.51331,-3.6714,-0.49139,-0.47918,-0.46803,-0.45745,-0.4451,-0.43318,-0.42116,-0.40904,-0.39655,-0.3898,-0.37043,-0.36156,-0.35279,-0.33142,-0.32108,-0.30668,-0.29876,-0.27897,-0.26621,-0.24911,-0.24169,-0.22196,-0.2166,-0.19837,-0.25596,-0.22804,-0.17736,-0.15345,-0.13039,-0.11732,-0.13144,-0.092691,-0.078537,-0.067352,-0.051406,-0.038769,-0.036741,-0.012716,-0.0059041,0.0093802,0.019368,0.034702,0.044414,0.055793,0.067129,-0.054226,-0.052306,
		-0.16919,-0.17436,-0.055546,-0.16989,-0.30453,-0.36914,-0.23298,-0.3607,-0.41728,-0.41116,-0.43528,-0.41374,-0.10889,-0.32699,-0.11563,-0.30712,-0.30458,-0.095263,0.26867,0.7348,-0.091114,-0.090808,0.71821,0.71975,0.71501,0.71226,1.0497,0.70559,1.0415,0.54185,0.54831,-1.9955,0.53575,0.53374,-1.9573,-1.9387,-1.9224,-1.9206,0.64168,0.51782,-0.84952,1.0573,0.44571,-1.3098,0.42327,0.39285,-3.1673,-2.9722,-3.0326,3.185,-1.1452,3.0305,-2.8638,-0.60585,-0.61845,2.9576,-1.5169,2.767,5.8724,2.5853,-0.61142,0.85788,-0.62344,-0.60165,-0.57046,-0.56352,-0.56554,0.28321,6.1777,0,-3.6654,0,0,0,0,4.87,4.6338,0,0,0,0,0.53317,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.11489,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
		-0.26964,-0.26957,-0.17428,-0.26519,-0.33516,-0.35239,-0.304,-0.33959,-0.32462,-0.31536,-0.24392,-0.10454,0.39222,0.098472,0.39671,0.10519,0.10835,0.38575,0.68608,0.7863,0.38799,0.38591,0.7434,0.73826,0.73331,0.72926,0.12143,0.72208,0.11721,-1.5061,-1.517,0.58752,-1.497,-1.4892,0.57918,0.57463,0.57085,0.57023,0,-1.4416,-1.8457,-0.12626,-1.3288,-1.8674,-1.2688,-1.2474,2.4641,2.3814,2.4365,-0.64044,-1.5608,-0.61222,2.3016,0,0,-0.60195,-1.7654,-0.56403,-2.4238,-0.525,0,-0.23899,0,0,0,0,0,0,-2.8959,0,0.56999,0,0,0,0,-0.58078,-0.55489,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
		-0.28274,-0.27886,-0.23391,-0.27468,-0.254,-0.2118,-0.27548,-0.20079,-0.11567,-0.10702,0.036729,0.22841,0.60789,0.44042,0.60258,0.42584,0.42688,0.5727,0.49078,-0.090806,0.56865,0.56649,-0.10686,-0.11345,-0.11138,-0.11315,-1.1985,-0.11294,-1.1883,0.51989,0.52425,0,0.51872,0.51645,0,0,0,0,0,0.50342,1.6758,-1.1517,-1.0441,2.0292,-0.97747,-0.93514,-0.56487,-0.5538,-0.5691,0,1.7107,0,-0.54011,0,0,0,0.85102,0,0.38254,0,0,0,0,0,0,0,0,0,0.51819,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
		-0.21894,-0.21156,-0.23207,-0.20923,-0.099946,-0.0096053,-0.16917,-0.0035577,0.12404,0.12639,0.27895,0.42283,0.32989,0.48865,0.32638,0.46231,0.46192,0.29909,-0.24197,-1.0317,0.2946,0.2925,-0.97179,-0.967,-0.9618,-0.95512,0.4781,-0.94613,0.47537,0,0,0,0,0,0,0,0,0,0,0,-0.40008,-0.5436,1.6237,-0.53609,1.5309,1.4888,0,0,0,0,-0.45433,0,0,0,0,0,1.9874,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
		-0.10223,-0.094039,-0.17763,-0.094026,0.0754,0.18605,-0.022393,0.18145,0.29997,0.29422,0.37636,0.36624,-0.30796,0.17858,-0.30441,0.16027,0.15802,-0.29485,-0.79846,0.46495,-0.29838,-0.297,0.44248,0.44261,0.44017,0.43786,0,0.43458,0,0,0,0,0,0,0,0,0,0,0,0,0,1.3157,-0.48518,0,-0.45821,-0.44791,0,0,0,0,0,0,0,0,0,0,-1.8163,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
		0.034838,0.040518,-0.087413,0.038399,0.21515,0.30165,0.122,0.28856,0.33662,0.32478,0.26968,0.057998,-0.69207,-0.33825,-0.69206,-0.32369,-0.32632,-0.64393,0.41623,0,-0.6395,-0.63664,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-0.44071,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.44756,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
		0.15533,0.15655,0.016567,0.15288,0.27383,0.28881,0.22165,0.27313,0.20206,0.1916,-0.014719,-0.3419,0.40212,-0.57268,0.40229,-0.53472,-0.53411,0.37752,0,0,0.378,0.37664,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
		0.22681,0.22321,0.11138,0.21863,0.22483,0.13895,0.2447,0.12784,-0.063238,-0.065181,-0.32991,-0.45854,0,0.37629,0,0.354,0.35538,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
		0.22596,0.21876,0.1755,0.2146,0.07427,-0.10306,0.17751,-0.10101,-0.32591,-0.31497,-0.37827,0.34342,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
		0,0,0.22461,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

typedef struct _wav2aud {
        t_object x_obj;
        
        // parametros do algortimo 
        t_float frmlen; 
        t_float tc;
        t_float fac;
        t_float shft;
        t_float filt;
        t_float VERB;
        t_float alpha;
        t_float beta;
        t_float L_frm;
        
        // leitura da array
        t_word *x_vec;
        t_symbol *x_arrayname;
    	int x_array_points;
        t_outlet *x_list;
        
                    
        
}t_wav2aud;

/*********************** INTERNAL FUNCTIONS  *******************************/
void filter(t_wav2aud *x, t_floatarg *B, t_floatarg *A, t_floatarg *wav){ 
	
	
}


void sigmoid(t_wav2aud *x, t_floatarg *y1, t_floatarg fac){ 
	
	
}


/******************* BANG MESSAGE - CLUSTERIZATION ***************************************/

void wav2aud_bang(t_wav2aud *x) {
	
	int i;
	t_atom *list_out;
	
	list_out = (t_atom *)getbytes(x->x_array_points*sizeof(t_atom));
	for(i=0; i<x->x_array_points; i++) SETFLOAT(list_out+i, x->x_vec[i].w_float);
			
	outlet_list(x->x_list, 0, x->x_array_points, list_out);

	// free local memory
	t_freebytes(list_out, x->x_array_points * sizeof(t_atom));
	
	
	post("r_COCHBA+0[3]= %f,r_COCHBA+1[3]= %f, r_COCHBA+2[3]= %f",r_COCHBA[0][1],r_COCHBA[1][1], r_COCHBA[2][1]);
	
    //outlet_list(x->x_obj.ob_outlet, gensym("list"), x->nData, saida);
}

/****************************** RIGHT INLET FUCTION **********************************/

		
		
/************************** OBJECT CREATION AND SETUP *************************************/

void *wav2aud_new(t_symbol *s, int argc, t_atom *argv){
     t_wav2aud *x = (t_wav2aud *)pd_new(wav2aud_class);
     
  
   // arguments: audio table,frameLength, timeconstante (leakyIntegr), nonlinear factor,  octave shift.   
  	switch(argc){
	case 5:
		x->shft = atom_getfloat(argv+4);
		x->fac = atom_getfloat(argv+3);
		x->alpha = exp(-1/atom_getfloat(argv+2) * pow(2, 4+x->shft));
		x->L_frm = round(atom_getfloat(argv+1) * pow(2, 4+x->shft));
		break;
	case 4:
		x->shft = -0.450;
		x->fac = atom_getfloat(argv+3);
		x->alpha = exp(-1/atom_getfloat(argv+2) * pow(2, 4+x->shft));
		x->L_frm = round(atom_getfloat(argv+1) * pow(2, 4+x->shft));
		break;	
	case 3:
		x->shft = -0.450;
		x->fac = -2;
		x->alpha = exp(-1/atom_getfloat(argv+2) * pow(2, 4+x->shft));
		x->L_frm = round(atom_getfloat(argv+1) * pow(2, 4+x->shft));
		break;
	case 2:
		x->shft = -0.450;
		x->fac = -2;
		x->alpha = exp(-1/8 * pow(2, 4+x->shft));
		x->L_frm = round(atom_getfloat(argv+1) * pow(2, 4+x->shft));
		break;		
	case 1:
		x->shft = -0.450;
		x->fac = -2;
		x->alpha = exp(-1/8 * pow(2, 4+x->shft));
		x->L_frm = round(8 * pow(2, 4+x->shft));
		break;
	case 0:
		x->shft = -0.450;
		x->fac = -2;
		x->alpha = exp(-1/8 * pow(2, 4+x->shft));
		x->L_frm = round(8 * pow(2, 4+x->shft));
								
	}
  	
	x->beta = exp(-1/0.5 * pow(2, 4+x->shft));
  	 	
 // acesso a array copiado do tabletool do brent 	
	t_garray *a;
 		
  		if(atom_getsymbol(argv))
  		{
  			x->x_arrayname = atom_getsymbol(argv);

  		    if(!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
  		        pd_error(x, "%s: no such array", x->x_arrayname->s_name);
  		    else if(!garray_getfloatwords(a, &x->x_array_points, &x->x_vec))
  		    	pd_error(x, "%s: bad template for tabletool", x->x_arrayname->s_name);	
  		}
  		else
  			post("WARNING: no array specified.");


  	  x->x_list = outlet_new(&x->x_obj, gensym("list")); 
     
     return (void *) x;
}

void wav2aud_free(t_wav2aud *x){
	
	freebytes(r_COCHBA, sizeof(float)*26*129);
	freebytes(i_COCHBA, sizeof(float)*26*129);
	
	
}
    
void wav2aud_setup(void) {
     wav2aud_class = class_new(gensym("wav2aud"), (t_newmethod)wav2aud_new, 
     (t_method)wav2aud_free, sizeof(t_wav2aud), CLASS_DEFAULT, A_GIMME, 0);
      
     //class_addlist(kmeans_class, kmeans_list);         
    class_addbang(wav2aud_class, wav2aud_bang);
    class_addmethod(wav2aud_class, (t_method)wav2aud_free, gensym("clear"),0);
 
}

